﻿@using Kingdee.WeksErp.Models.Orders
@model Kingdee.WeksErp.Models.Orders.TbOrder

@{
    ViewBag.Title = "比价分析";
    Layout = "~/Views/Shared/_LayoutEasyUI.cshtml";
}
<style>
    .datagrid-header-row div {
        text-align: center;
        white-space: normal;
        height: auto;
    }
</style>
<table id="grid-list"> </table>

<div id="toolbar" style="display:none;">
    <div style="margin: 10px 0 5px 20px; ; height: 35px;">
        <input id="cbSupplier" type="text">
        @if (Model.Status == OrderStatus.Dispathed)
        {
            <a id="btnConfirm" href="#" class="easyui-linkbutton btn" data-options="iconCls:'icon-man'">确认物流</a>
        }
    </div>
</div>

@section scripts{
    <script>
        var OrderId = @Model.FOrderId;
        $(function() {
            Grid.LoadData();
            initSuppliers();

            $('#btnConfirm').click(function() {
                var index = layer.confirm('确认物流比价结果？', function(index) {
                    layer.close(index);
                    $.ajax({
                        url: '/Order/ConfirmBj',
                        data: {
                            orderid: OrderId,
                            supplierid: $('#cbSupplier').combobox('getValue')
                        },
                        type: 'post',
                        dataType: 'json',
                        success: function(data) {
                            if (data.success) {
                                parent.Grid.Refresh();
                                parent.Grid.CloseDetail();
                            } else {
                                layer.msg("确认失败！"+data.msg);
                            }
                        },error: function(XMLHttpRequest, textStatus, errorThrown) {
                            layer.msg(textStatus);
                        }
                    });
                });
            });
        });

        var Grid = {
            LoadData: function() {
                var url = "/Order/BjDetail?orderid=" + OrderId;
                Grid.list = $("#grid-list").datagrid({
                    url: url,
                    fit: true,
                    fitColumns: true,
                    singleSelect: false,
                    rownumbers: true,
                    nowrap: false,
                    striped: true, //隔行变色
                    toolbar: '#toolbar',
                    columns: [
                        [
                            { field: 'SupplierName', title: '物流', width: 100, align: 'center' },
                            { field: 'FCost1', title: '报价（入户）', width: 100, align: 'center' },
                            { field: 'FCost2', title: '报价（不入户）', width: 100, align: 'center' }
                        ]
                    ]
                });
            },
            Refresh: function() {
                Grid.list.datagrid('reload');
            }
        }

        function initSuppliers() {
            $('#cbSupplier').combobox({
                url: '/Order/SupplierDispathed?orderid=' + OrderId,
                valueField: 'FItemId',
                textField: 'FName',
                panelHeight: 'auto',
                editable:false,
                onLoadSuccess: function() {
                    $('#cbSupplier').combobox('setValue', @Model.FSupplierId);
                }
            });
        }
    </script>
}
